﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;
using System.Xml;

namespace WebRaoVat.Admin
{
    public partial class QuanLyTheme : System.Web.UI.Page
    {
        public string themeCheck = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["LaAdmin"] == null || Session["LaAdmin"].ToString().Length <= 0)
            {                
                //Response.Redirect("../Default.aspx");
            }

            if (!IsPostBack)
            {
                themeCheck = ((XmlElement)XL_XML.ReadNodeSingle(XL_XML.ReadDocumentFile(Server.MapPath("~/Gui.xml")),
            "/GIAODIEN/THEME")).GetAttribute("ten");
                if(themeCheck.Equals("theme1"))
                    RadioButton1.Checked = true;
                else if(themeCheck.Equals("theme2"))
                    RadioButton2.Checked = true;
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            string themeChon = "theme2";
            if (RadioButton1.Checked)
                themeChon = "theme1";
            else if (RadioButton2.Checked)
                themeChon = "theme2";
            
            XmlDocument taiLieu = null;
            try
            {
                taiLieu = XL_XML.ReadDocumentFile(Server.MapPath("../Gui.xml"));
            }
            catch { }
            if (taiLieu == null)
                return;

            XL_XML.DeleteNode(taiLieu, "//GIAODIEN/THEME");// xóa MENU cũ ra
            CapNhatTheme(taiLieu, themeChon);

            XL_XML.WriteDocument(taiLieu, Server.MapPath("../Gui.xml"));
        }

        public void CapNhatTheme(XmlDocument taiLieu, string theme)
        {
            List<string> tenThuocTinh = new List<string>();
            List<string> giaTriThuocTinh = new List<string>();
            tenThuocTinh.Add("NgayDoi"); giaTriThuocTinh.Add(DateTime.Now.ToString());
            tenThuocTinh.Add("ten"); giaTriThuocTinh.Add(theme);

            XmlNode ThemeNode = XL_XML.CreateNode(taiLieu, "THEME", tenThuocTinh, giaTriThuocTinh);
            XL_XML.AddNode(taiLieu, "//GIAODIEN", ThemeNode);
        }

    }
}
